package com.molichuxing.services.infrastructure.service.impl;
import com.molichuxing.services.infrastructure.bean.AccountDealerBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.AccountDealerMapper;
import com.molichuxing.services.infrastructure.dto.response.response.AccountDealerDto;
import com.molichuxing.services.infrastructure.service.AccountDealerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("accountDealerService")
public class AccountDealerServiceImpl implements AccountDealerService {
    private static final Logger logger = LoggerFactory.getLogger(AccountDealerServiceImpl.class);

    @Resource
    private AccountDealerMapper accountDealerMapper;
    /**
     * 获取账户关联经销商id
     *
     * @param accountId 账户id
     * @return
     */
    @Override
    public AccountDealerDto getAccountDealer(Integer accountId) {
        AccountDealerDto result = null;
        List<AccountDealerBean> accountDealers = accountDealerMapper.getAccountDealer(accountId);
        if (accountDealers == null || accountDealers.isEmpty()) {
            return result;
        }
        result = Convert.toAccountDealerDto(accountDealers.get(0));
        return result;
    }

    @Override
    public List<AccountDealerDto> getAccountDealerByParam(Map<String, Object> param) {
        List<AccountDealerBean> beanList = accountDealerMapper.getAccountDealerByParam(param);
        return Convert.toAccountDealerDtoList(beanList);
    }

    @Override
    public int createAccountDealer(AccountDealerDto dto) {
        AccountDealerBean bean = Convert.toAccountDealerBean(dto);
        int row = accountDealerMapper.createAccountDealer(bean);
        if (row > 0) {
            return bean.getId();
        }
        return 0;
    }

    @Override
    public int deleteByAccountId(int accountId) {
        return accountDealerMapper.deleteByAccountId(accountId);
    }
}
